package com.sky.directdeal.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sky.directdeal.R;
import com.sky.local_ads.sub_category.SubCategoryList;

public class SubCategoryListAdapter extends BaseAdapter {
private Context context;
private List<SubCategoryList> subCategoryLists;
	


	public SubCategoryListAdapter(Context context,
		List<SubCategoryList> subCategoryLists) {
	super();
	this.context = context;
	this.subCategoryLists = subCategoryLists;
}

	@Override
	public int getCount() {
		return subCategoryLists.size();
	}

	@Override
	public Object getItem(int position) {
		return subCategoryLists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		if (convertView == null) {

			convertView = inflater.inflate(R.layout.sub_cat_row_layout,
					parent, false);
			holder = new ViewHolder();
			holder.subcategotyText = (TextView) convertView
					.findViewById(R.id.textViewSubCategoryItem);
			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();

		}

		final SubCategoryList subCategoryList = (SubCategoryList) getItem(position);
		
		if(subCategoryList!=null) {
			String subCatName="LOCAL STORE";
			
			if(subCategoryList.getSubCategoryName()!=null) {
				subCatName=subCategoryList.getSubCategoryName();
			}
			holder.subcategotyText.setText(subCatName);
			
		}
		
		return convertView;
	}
	private static class ViewHolder {

		private TextView subcategotyText;
	}

}
